﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<DTTB.MV2.QUANLYNHANSUTIENLUONG.Models.FormBean.PhanQuyen.PermissionsPublicForm>" %>

<%@ Import Namespace="Webdiyer.WebControls.Mvc" %>
<%@ Import Namespace="DTTB.DTO" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/formatcurrency/jquery.formatCurrency.js") %>"></script>

    <script type="text/javascript" src="<%= ResolveUrl("~/Scripts/formatcurrency/i18n/jquery.formatCurrency.all.js") %>"></script>

    <script type="text/javascript" src="<%= ResolveUrl("~/Content/Scripts/User/PermissionsAllUsers.js") %>"></script>

    <%Html.BeginForm(); %>
    <input type="hidden" id="NewPermissionsPublicString" name="NewPermissionsPublicString" value="" />

    <%--<div class="module">--%>
     <div class="box">
     <!-- box / title -->
		<div class="title">
			<h5>&nbsp;Set Permissions Public</h5>
		</div>
		<!-- end box / title -->
       <%-- <div class="module_top"></div>--%>
        <%--<div class="contain_module">--%>
            <table class="table_outsite">
                <%--<tr class="title">
                    <td colspan="2" class="first">
                        &nbsp;Set Permissions Public
                    </td>
                    <td colspan="2" class="first" align="right">
                        &nbsp; &nbsp;
                    </td>
                </tr>--%>
                <tr>
                    <td align="left" id="NoteMessage1">
                        <strong>
                            <%if (Model.message == "Successfully Updated !")
                                {
                            %>
                            <span style="color: Blue">
                                <%=Model.message%></span>
                            <%
                                }
                                else if (Model.message == "Update Failed, Please try again !")
                                {%>
                            <span style="color: Red">
                                <%=Model.message%></span>
                            <%}%>
                        </strong>
                    </td>
                    <td align="right">
                            
                        <input type="button" class="button2" name="Update" id="Button1" value="Update" onclick="onUpdate();" />&nbsp;
                        <input type="reset" class="button2" value="Reset" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <table border="1" style="border-collapse:collapse" cellspacing="0" cellpadding="0" class="table_module">
                            <tr class="title">
                                <td width="37%" class="first">
                                    &nbsp;<b>Module(s)</b>
                                </td>
                                <td width="21%" align="center" class="first">
                                    &nbsp;<b>Create/Edit/Update</b>
                                </td>
                                <td width="21%" align="center" class="first">
                                    &nbsp;<b>View/List</b>
                                </td>
                                <td width="21%" align="center" class="first">
                                    &nbsp;<b>Delete</b>
                                </td>
                            </tr>
                            <%for (int i = 0; i < Model.Modules.Count; i++)
                            {
                            %> 
                              <tr onclick="highlight(this); doClickCheckbox()" class="item_row">
                                <td>
                                    &nbsp;<%=Model.Modules[i]%>
                                </td>
                                <%--Case1 : Permission : Create/Edit/Update | Build CheckBox--%>
                                <%
                                    bool checkBoxFlag1 = false;
                                    for (int j = 0; j < Model.PathsList.Count; j++)
                                    {
                                        if ((Model.PathsList[j].Modules == Model.Modules[i]) && (Model.PathsList[j].PermissionType == "Create_Edit_Update"))
                                        {
                                            checkBoxFlag1 = true;
                                            bool checkedFlag = false;
                                            for (int k = 0; k < Model.PathsForAllUsersList.Count; k++)
                                            {
                                                if ((Model.PathsForAllUsersList[k].Modules == Model.Modules[i]) && (Model.PathsForAllUsersList[k].PermissionType == "Create_Edit_Update"))
                                                {%>
                                <td align="center">
                                    <input id="<%= Model.Modules[i] + "-" + Model.PathsForAllUsersList[k].PermissionType%>"
                                        type="checkbox" value="<%=Model.PathsForAllUsersList[k].ID %>" checked="checked"
                                        onclick="unSelectCreate('<%=Model.Modules[i]%>','<%=Model.PathsForAllUsersList[k].PermissionType %>');" />&nbsp;
                                </td>
                                <%
                                    checkedFlag = true;
                                    break;
                                                }
                                            }

                                            if (checkedFlag == false)
                                            {%>
                                <td align="center">
                                    <input id="<%=Model.Modules[i]+ "-Create_Edit_Update"%>" type="checkbox" value="<%=Model.PathsList[j].ID %>"
                                        onclick="unSelectCreate('<%=Model.Modules[i]%>','-Create_Edit_Update');" />&nbsp;
                                </td>
                                <%}
                                                break;
                                        }
                                    }
                                    if (checkBoxFlag1 == false)
                                    {
                                %>
                                <td align="center">
                                    &nbsp;
                                </td>
                                <%
                                    }
                                
                                %>
                                <%--Case2 : Permission : View/List | Build CheckBox--%>
                                <%
                                    bool checkBoxFlag2 = false;
                                    for (int j1 = 0; j1 < Model.PathsList.Count; j1++)
                                    {
                                        if ((Model.PathsList[j1].Modules == Model.Modules[i]) && (Model.PathsList[j1].PermissionType == "View_List"))
                                        {
                                            checkBoxFlag2 = true;
                                            bool checkedFlag = false;
                                            for (int k = 0; k < Model.PathsForAllUsersList.Count; k++)
                                            {
                                                if ((Model.PathsForAllUsersList[k].Modules == Model.Modules[i]) && (Model.PathsForAllUsersList[k].PermissionType == "View_List"))
                                                {%>
                                <td align="center">
                                    <input id="<%=Model.Modules[i] + "-" + Model.PathsForAllUsersList[k].PermissionType%>"
                                        value="<%=Model.PathsForAllUsersList[k].ID %>" type="checkbox" checked="checked"
                                        onclick="unSelectView('<%=Model.Modules[i] %>','<%=Model.PathsForAllUsersList[k].PermissionType %>');" />&nbsp;
                                </td>
                                <%
                                    checkedFlag = true;
                                    break;
                                                }
                                            }

                                            if (checkedFlag == false)
                                            {%>
                                <td align="center">
                                    <input id="<%=Model.Modules[i]+ "-View_List"%>" value="<%=Model.PathsList[j1].ID %>"
                                        type="checkbox" onclick="unSelectView('<%=Model.Modules[i] %>','-View_List');" />&nbsp;
                                </td>
                                <%}
                                                break;
                                        }
                                    }
                                    if (checkBoxFlag2 == false)
                                    {
                                %>
                                <td align="center">
                                    &nbsp;
                                </td>
                                <%
                                    }    
                                %>
                                <%--Case3 : Permission : Delete | Build CheckBox--%>
                                <%
                                    bool checkBoxFlag3 = false;
                                    for (int j2 = 0; j2 < Model.PathsList.Count; j2++)
                                    {
                                        if ((Model.PathsList[j2].Modules == Model.Modules[i]) && (Model.PathsList[j2].PermissionType == "Delete"))
                                        {
                                            checkBoxFlag3 = true;
                                            bool checkedFlag = false;
                                            for (int k = 0; k < Model.PathsForAllUsersList.Count; k++)
                                            {
                                                if ((Model.PathsForAllUsersList[k].Modules == Model.Modules[i]) && (Model.PathsForAllUsersList[k].PermissionType == "Delete"))
                                                {%>
                                <td align="center">
                                    <input id="<%=Model.Modules[i] + "-" + Model.PathsForAllUsersList[k].PermissionType %>"
                                        type="checkbox" value="<%=Model.PathsForAllUsersList[k].ID %>" checked="checked"
                                        onclick="unSelectDelete('<%=Model.Modules[i] %>','<%=Model.PathsForAllUsersList[k].PermissionType %>');" />&nbsp;
                                </td>
                                <%
                                    checkedFlag = true;
                                    break;
                                                }
                                            }

                                            if (checkedFlag == false)
                                            {%>
                                <td align="center">
                                    <input id="<%=Model.Modules[i] + "-Delete"%>" type="checkbox" value="<%=Model.PathsList[j2].ID %>"
                                        onclick="unSelectDelete('<%=Model.Modules[i] %>','-Delete');" />&nbsp;
                                </td>
                                <%}
                                                break;
                                        }
                                    }
                                    if (checkBoxFlag3 == false)
                                    {
                                %>
                                <td align="center">
                                    &nbsp;
                                </td>
                                <%
                                    }       
                                %>
                            </tr>
                            <%
                                }%>
                        </table>
                    </td>
                </tr>
            
                <tr>
                    <td align="left" id="NoteMessage2">
                        <strong>
                            <%if (Model.message == "Update is completed !")
                                {
                            %>
                            <span style="color: Blue">
                                <%=Model.message%></span>
                            <%
                                }
                                else if (Model.message == "Update is not completed ! Please try again.")
                                {%>
                            <span style="color: Red">
                                <%=Model.message%></span>
                            <%}%>
                        </strong>
                    </td>
                    <td colspan="4" align="right">
                            
                        <input type="button" class="button2" name="Update" id="Update" value="Update" onclick="onUpdate();" />&nbsp;
                        <input type="reset" class="button2" value="Reset" />
                    </td>
                </tr>
            </table>
       <%--</div>--%>
    </div>
 
    <%Html.EndForm(); %>

    <script language="javascript" type="text/javascript">

        function onUpdate() {
            for (var i = 0; i < document.forms[0].length; i++) {
                var e = document.forms[0].elements[i];
                if (e.type == 'checkbox' && e.checked) {
                    document.getElementById("NewPermissionsPublicString").value = document.getElementById("NewPermissionsPublicString").value + "|" + e.id;
                }
            }
            document.forms[0].action = '<%=ResolveUrl("~/PermissionsPublic/SetPermissionsPublicUpdate/")%>';
            document.forms[0].method = "Post";
            document.forms[0].submit();
        }

        function doClickCheckbox() {
            document.getElementById('NoteMessage1').innerHTML = "";
            document.getElementById('NoteMessage1').innerHTML = "";
        }
    </script>

</asp:Content>
